<?php

/**
 * @Author: Wang Chunsheng 2192138785@qq.com
 * @Date:   2020-03-10 04:14:17
 * @Last Modified by:   Wang Chunsheng 2192138785@qq.com
 * @Last Modified time: 2020-03-16 16:25:29
 */


namespace api\modules\diandi_shop\controllers;

use Yii;
use api\controllers\AController;
use api\modules\diandi_shop\services\GoodsService;
use common\helpers\ResultHelper;

/**
 * Class GoodsController
 */
class GoodsController extends AController
{
    public $modelClass = '\common\models\DdGoods';
    protected $authOptional = ['*'];

    /**
     * @SWG\Get(path="/diandi_shop/goods/search",
     *     tags={"商品"},
     *     summary="商品检索",
     *     @SWG\Response(
     *          response = 200,
     *          description = "关键词商品检索",
     *          @SWG\Schema(ref = "#/definitions/Goods")
     *     ),
     *     @SWG\Parameter(
     *          in="query",
     *          name="page",
     *          type="integer",
     *          description="分页",
     *          required=true,
     *   ),
     *   @SWG\Parameter(
     *          in="query",
     *          name="pageSize",
     *          type="integer",
     *          description="显示条数",
     *          required=true,
     *   ),
     *   @SWG\Parameter(
     *          in="query",
     *          name="keyword",
     *          type="string",
     *          description="关键词",
     *          required=false,
     *   ),
     * )
     */
    public function actionSearch()
    {
        $keytwords = Yii::$app->request->get('keytwords');
        $pageSize = Yii::$app->request->get('pageSize');
        $list = GoodsService::getList(0, 0, $keytwords, $pageSize);
        return ResultHelper::json(200, '获取成功', $list);
    }
    /**
     * @SWG\Post(path="/diandi_shop/goods/Detail",
     *     tags={"商品"},
     *     summary="Retrieves the collection of Goods resources.",
     *     @SWG\Response(
     *         response = 200,
     *         description = "Goods collection response",
     *         @SWG\Schema(ref = "#/definitions/Goods")
     *     ),
     *     @SWG\Parameter(
   *     in="formData",
   *     name="reason && ninini",
   *     type="string",
   *     description="需要的字段",
   *     required=true,
   *   ),
     * )
     */
    public function actionDetail()
    {
        return 43;
    }

    /**
     * @SWG\Get(path="/diandi_shop/goods/lists",
     *     tags={"商品"},
     *     summary="Retrieves the collection of Goods resources.",
     *     @SWG\Response(
     *          response = 200,
     *          description = "Goods collection response",
     *          @SWG\Schema(ref = "#/definitions/Goods")
     *     ),
     *     @SWG\Parameter(
     *          in="query",
     *          name="page",
     *          type="string",
     *          description="分页",
     *          required=true,
     *   ),
     *   @SWG\Parameter(
     *          in="query",
     *          name="pageSize",
     *          type="string",
     *          description="显示条数",
     *          required=true,
     *   ),
     *   @SWG\Parameter(
     *          in="query",
     *          name="category_pid",
     *          type="integer",
     *          description="父级分类id",
     *          required=false,
     *   ),
     *   @SWG\Parameter(
     *          in="query",
     *          name="category_id",
     *          type="integer",
     *          description="分类id",
     *          required=false,
     *   ),
     * )
     */
    public function actionLists()
    {
        $data = Yii::$app->request->get();
        $pageSize = Yii::$app->request->get('pageSize');
        $list = GoodsService::getList($data['category_pid'], $data['category_id'], '', $pageSize);
        return ResultHelper::json(200, '获取成功', $list);
    }
}
